#drafted by Jeremy VanDerWal ( jjvanderwal@gmail.com ... www.jjvanderwal.com )
#GNU General Public License .. feel free to use / distribute ... no warranties

################################################################################
################################################################################
#set some constants

#set the working dir and output dir
work.dir = '/home1/99/jc152199/brt/data/'; setwd(work.dir)
script.file = '/home1/99/jc152199/brt/data/batch.brt.torun.r'
################################################################################
#do something

#get a list of all the learning rates
lr.list = c(.5,.1)

for (lrs in lr.list) {
	#create a folder for the species
	dir.create(paste(work.dir,lrs,"/",sep=""))
	lr.folder = paste(work.dir,lrs,"/",sep="")
	setwd(lr.folder)
	lr.arg = paste('lr="',lrs,'" ',sep='')
	lr.dir.arg = paste('lr.dir="',work.dir,'" ',sep='')
	
	##create the sh file
	zz = file(paste('batch.brt.',lrs,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd ',lr.folder,'\n',sep='',file=zz)
		cat("R CMD BATCH '--args ",lr.arg,lr.dir.arg,"' ",script.file,' batch.brt.Rout --no-save \n',sep='',file=zz)
		cat('##################################\n',file=zz)
	close(zz)
			
	#submit the job
	system(paste('qsub -m n -l nodes=1:ppn=8 batch.brt.',lrs,'.sh',sep=''))
}
	
